package com.example.recordingpen_datacollection.AIBDText;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AIKerDuo {
    @Test
    public void test(){
        Map <String, Server> map = serverPar();
        Map<String, Server> map1 = TestSetver(map);
        for (Map.Entry<String, Server> entry : map1.entrySet()) {
        }


    }

    @Test
    public void test2(){
        List<Server> serverList = serverParList();
        List<Server> serverList1 = CSAIKer.TestSetver(serverList);
        for (Server server : serverList1) {
            System.out.println(server);
        }


    }

    /**
     * 测试服务
     * @return
     */
    public Map TestSetver(Map<String, Server> map){
        Server serverSigo = null;
        /**
         * 查询标记为1的
         */
        for (int x = 0; x < 10 ; x++) {
            Server server = map.get("N：" + x);
            if(server.getSign() ==1){
                serverSigo = server;
                break;
            }

        }

        int sign = 0;
        for (int i = 0; i < 13; i++) {


            //更改标记
            for (int j = 0; j < map.size() && sign==3; j++) {
                Server server = map.get("N：" + j);
                System.out.println("j->" + j);
                System.out.println(server.getSign() ==1);
                //修改
                if(server.getSign() ==1){
                    server.setSign(0);
                    map.put("N："+j,server);
                    System.out.println("map.containsKey(\"N：\"+i+1)->"+map.containsKey("N："+(j+1))+": j+1: " +(j+1));
//                    System.out.println("map.containsKey(\"N：\"+i+1)->"+map.containsKey("N："+(j+1)) +": j+1" +(j));
                    if(map.containsKey("N："+(j+1))){
                        Server server2 = map.get("N：" + j);
                        server2.setSign(0);
                        map.put("N：" + j,server2);

                        Server server1 = map.get("N：" + (j+1));
                        server1.setSign(1);
                        map.put("N：" + (j+1),server1);
                        serverSigo = server1;
                    } else {
                        Server server2 = map.get("N：" + j);
                        server2.setSign(0);
                        map.put("N：" + j,server2);

                        Server server1 = map.get("N：" + 0);
                        server1.setSign(1);
                        map.put("N：" + 0,server1);
                        serverSigo = server1;
                    }
                    System.out.println("sign = 0;");
                    sign = 0;
                    break;
                }

            }
            sign++;
            System.out.println("sign++ ："+sign);
            serverSigo.setTime(serverSigo.getTime()+1);
        }
        return map;
    }








    public Map serverPar(){
        Map <String, Server> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {

            if(i==0){

                Server server = new Server("name->"+i,0,1);
                map.put("N："+i,server);
            } else {
                Server server = new Server("name->"+i,0,0);
                map.put("N："+i,server);
            }

        }

        return map;
    }




    public List<Server> serverParList(){
        List<Server> serverList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            if(i==5){
                Server server = new Server("name->"+i,0,1);
                serverList.add(server);
            } else {
                Server server = new Server("name->"+i,0,0);
                serverList.add(server);
            }

        }
        return serverList;
    }


    // 模拟的服务器类
    class Server {
        private  String name;
        private  int time;
        private  int sign;

        public Server(String name, int time, int sign) {
            this.name = name;
            this.time = time;
            this.sign = sign;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getTime() {
            return time;
        }

        public void setTime(int time) {
            this.time = time;
        }

        public int getSign() {
            return sign;
        }

        public void setSign(int sign) {
            this.sign = sign;
        }

        @Override
        public String toString() {
            return "Server{" +
                    "name='" + name + '\'' +
                    ", time=" + time +
                    ", sign=" + sign +
                    '}';
        }
    }

    @Test
    public void cs(){
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);
        list.add(7);
        list.add(8);
        list.add(9);


        list.remove(2);
        list.add(2,3);

        for (Integer integer : list) {
            System.out.println(integer);
        }
    }
}



